﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using SXICE.Core.Helpers;
using SXICE.Core.Models;
using System.Linq;

namespace SXICE.WebAPI.Filters
{
    /// <summary>
    /// 验证空实体过滤器
    /// </summary>
    public class ValidateNullModelAttribute : IActionFilter
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            //var param = context.ActionDescriptor.Parameters?.FirstOrDefault();
            //if (!param?.ParameterType?.IsClass ?? true && (param?.ParameterType?.IsPrimitive ?? true) || (param?.ParameterType?.IsValueType ?? true))
            //    return;
            //if (context.ActionArguments.ContainsKey(param.Name) && null == context.ActionArguments[param.Name])
            //    context.Result = new OkObjectResult(ErrorCode.NULL_MODEL.ToResult<string>("数据不能为空"));
        }
    }
}
